package com.teradata.tool.dao;

import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.teradata.tool.bean.GlAcctCheckInfoBean;
import com.teradata.tool.db.DbUtil;

public class GlAcctCheckDao {
	private static final String	QUERY_GL_ACCT_CHECK_INFOS	= "select Check_Id,Check_Dt,Check_db,Check_GL_Tab,Org_Id,Ccy_Cd,Item_Id,Deb_Crd_Ind,Acct_Bal,Gl_Bal from "
																	+ DbUtil.getDbConfigurationInfo().getDbDqc()
																	+ ".T11_GL_ACCT_CHECK_DETAIL where CHECK_DT>=? and CHECK_DT<=? AND Acct_Bal <> Gl_Bal ORDER BY CHECK_DT,Check_Id,Org_Id,Ccy_Cd,Item_Id;";

	public static List<GlAcctCheckInfoBean> queryGlAcctCheckInfoBeans(Connection conn, Date txdate_start,
			Date txdate_end) throws SQLException {
		List<GlAcctCheckInfoBean> ret = new ArrayList<GlAcctCheckInfoBean>();
		PreparedStatement stat = conn.prepareStatement(QUERY_GL_ACCT_CHECK_INFOS);
		try {
			stat.setDate(1, txdate_start);
			stat.setDate(2, txdate_end);
			ResultSet rs = stat.executeQuery();
			try {
				while (rs.next()) {
					GlAcctCheckInfoBean info = new GlAcctCheckInfoBean();
					int i = 1;
					info.setCheckId(rs.getString(i++));
					info.setCheckDt(rs.getDate(i++));
					info.setCheckDb(rs.getString(i++));
					info.setCheckGlTab(rs.getString(i++));
					info.setOrgId(rs.getString(i++));
					info.setCcyCd(rs.getString(i++));
					info.setItemId(rs.getString(i++));
					info.setDeb_Crd_Ind(rs.getString(i++));
					// info.setGlCnt(rs.getInt(i++));
					info.setAcctBal(rs.getDouble(i++));
					info.setGlBal(rs.getDouble(i++));
					ret.add(info);
				}
			} finally {
				rs.close();
			}
		} finally {
			stat.close();
		}
		return ret;
	}
}
